package util;

import org.json.JSONObject;

import com.baidu.aip.ocr.AipOcr;

/*
 * 调用百度大脑识别车牌
 */
public class RecongnizationByAI {
	public static final String APP_ID = "10525529";
    public static final String API_KEY = "fSXM7nSPGW9qBItxjlNUy3yH";
    public static final String SECRET_KEY = "48q3SxgTDCEKmOfbkIcCofoGMGkKgRtL";
	
	String imagePath = "";
	
	//获取UploadImgServlet拿到的图片绝对路径
	public RecongnizationByAI(String path){
		imagePath = path;
	}
	
	public static String Recongnize(String imagePath) {
		AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);

		client.setConnectionTimeoutInMillis(2000);
		client.setSocketTimeoutInMillis(60000);
		
		JSONObject json_result = client.plateLicense(imagePath);
		String str_result = json_result.get("words_result").toString();
		String [] results = str_result.split("\"");
		for(int i=0;i<results.length;i++){
			System.out.println(results[i]);
		}
		return results[3]; 
	}
	 

}
